package com.pi.shisan.component.util;

import com.pi.shisan.common.NumberUtil;
import com.pi.shisan.util.spipoint.MultipleXyToSpiConverter;

public class SharedMethod {

    /**
     * @param points 原始坐标
     * @param startX
     * @param startY
     * @param fromX
     * @param fromY
     * @param maxX
     * @param maxY
     * @param width
     * @param height
     * @param spi
     * @param lastAllPoints
     * @return
     */
    public static int drawPoints(int[] points, int startX, int startY, int fromX, int fromY, int maxX, int maxY, int width, int height, MultipleXyToSpiConverter spi, FastIntList lastAllPoints) {
        for (int i = 0; i < points.length; i++) {
            int xy = points[i];
            int vx = NumberUtil.toX(xy);
            maxX = Math.max(maxX, vx);
            vx += startX +fromX;
            int vy = NumberUtil.toY(xy);
            maxY = Math.max(maxY,vy);
            vy += startY + fromY;
            if (vx < startX) {
                continue;
            }
            if (width > 0 && vx >= width + startX) {
                continue;
            }
            if (vy < startY) {
                continue;
            }
            if (height > 0 && vy >= height + startY) {
                continue;
            }
            spi.put(vx ,vy);
            lastAllPoints.add(NumberUtil.toXy((short) vx, (short) vy));
        }
        return NumberUtil.toXy((short)maxX, (short)maxY);
    }

}
